const sql = require('mssql');

// 登录
const loginIn = async (ctx) => {
    try {
        const { userName, password } = ctx.request.body;
        let selectSql = ` SELECT BM,MC,DLMC FROM BM_YG WHERE (MC = '${userName}' OR DLMC = '${userName}') AND MM = '${password}' `;
        let result = await sql.query(selectSql);
        if (result.rowsAffected[0] > 0) {
            ctx.body = {
                code: 200,
                message: '登录成功',
                result: result.recordset[0]
            }
        } else {
            ctx.body = {
                code: 400,
                message: '登录失败'
            }
        }

    } catch (err) {
        let message = 'originalError' in err ? err.originalError.info.message : '服务器错误'
        ctx.body = {
            code: 500,
            message
        }
    }
}

module.exports = {
    'POST /loginIn': loginIn
}